﻿Imports System.IO
Imports iComm.DB
Public Class ClsMail

    Sub New()

    End Sub

    Public Function select_viw_mail_account() As DataTable

        Dim clsSQL As New MysqlHelper()

        Try
            Dim clsUtilities As New DB.MysqlUtilities()
            Return clsSQL.GetSQLdataTbl(clsUtilities.SQL_select_viw_mail_account)

        Catch ex As Exception
            SystemError.SystemLog(ex)
            Return Nothing
        Finally
            clsSQL.Dispose()
            clsSQL = Nothing

        End Try
    End Function

    Public Function select_mailuid(ByVal intAccountId As Integer) As DataTable

        Dim clsSQL As New MysqlHelper()

        Try
            Dim clsUtilities As New DB.MysqlUtilities()
            clsUtilities.SQL_select_dat_mail_uid_value(0).ParamValue = intAccountId
            Dim param As MySql.Data.MySqlClient.MySqlParameter() = clsUtilities.GetParam(clsUtilities.SQL_select_dat_mail_uid_value)
            Return clsSQL.GetSQLdataTbl(clsUtilities.SQL_select_dat_mail_uid, param)

        Catch ex As Exception
            SystemError.SystemLog(ex)
            Return Nothing
        Finally
            clsSQL.Dispose()
            clsSQL = Nothing

        End Try
    End Function

    Public Function select_mst_mail_filter(ByVal intAccountId As Integer) As DataTable

        Dim clsSQL As New MysqlHelper()

        Try
            Dim clsUtilities As New DB.MysqlUtilities()
            clsUtilities.SQL_select_mst_mail_filter_value(0).ParamValue = intAccountId
            Dim param As MySql.Data.MySqlClient.MySqlParameter() = clsUtilities.GetParam(clsUtilities.SQL_select_mst_mail_filter_value)
            Return clsSQL.GetSQLdataTbl(clsUtilities.SQL_select_mst_mail_filter, param)

        Catch ex As Exception
            SystemError.SystemLog(ex)
            Return Nothing
        Finally
            clsSQL.Dispose()
            clsSQL = Nothing

        End Try
    End Function

    Public Function select_mst_filter(ByVal intAccountId As Integer) As DataTable

        Dim clsSQL As New MysqlHelper()

        Try
            Dim clsUtilities As New DB.MysqlUtilities()
            clsUtilities.SQL_select_mst_filter_value(0).ParamValue = intAccountId
            Dim param As MySql.Data.MySqlClient.MySqlParameter() = clsUtilities.GetParam(clsUtilities.SQL_select_mst_filter_value)
            Return clsSQL.GetSQLdataTbl(clsUtilities.SQL_select_mst_filter, param)

        Catch ex As Exception
            SystemError.SystemLog(ex)
            Return Nothing
        Finally
            clsSQL.Dispose()
            clsSQL = Nothing

        End Try
    End Function

    ''' <summary>
    ''' ローカルフォルダ構造をDBサーバに登録
    ''' </summary>
    ''' <returns>処理結果</returns>
    ''' <exception cref="Exception">処理失敗</exception>
    Public Function insert_mailinfo(ByVal SQL_insert_dat_mail_info_Value As iComm.DB.MysqlUtilities.STC_Item()) As Integer

        Dim clsSQL As New MysqlHelper()
        Dim intResult As Integer = 0
        Try

            '
            Dim clsUtilities As New DB.MysqlUtilities()
            clsUtilities.SQL_insert_dat_mail_info_Value = SQL_insert_dat_mail_info_Value
            Dim param As MySql.Data.MySqlClient.MySqlParameter() = clsUtilities.GetParam(clsUtilities.SQL_insert_dat_mail_info_Value)
            intResult = clsSQL.RunSQL(clsUtilities.SQL_insert_dat_mail_info, param)

            Return intResult
        Catch ex As Exception
            SystemError.SystemLog(ex)
            Return -1
        Finally
            clsSQL.Dispose()
            clsSQL = Nothing
        End Try
    End Function

    ''' <summary>
    ''' メールパスワードを暗号化し、DBに保存
    ''' </summary>
    ''' <returns>処理結果</returns>
    ''' <exception cref="Exception">処理失敗</exception>
    Public Function update_mailaccount(ByVal SQL_update_mst_mail_account_value As iComm.DB.MysqlUtilities.STC_Item()) As Integer

        Dim clsSQL As New MysqlHelper()
        Dim intResult As Integer = 0
        Try

            '
            Dim clsUtilities As New DB.MysqlUtilities()
            clsUtilities.SQL_update_mst_mail_account_value = SQL_update_mst_mail_account_value
            Dim param As MySql.Data.MySqlClient.MySqlParameter() = clsUtilities.GetParam(clsUtilities.SQL_update_mst_mail_account_value)
            intResult = clsSQL.RunSQL(clsUtilities.SQL_update_mst_mail_account, param)

            Return intResult
        Catch ex As Exception
            SystemError.SystemLog(ex)
            Return -1
        Finally
            clsSQL.Dispose()
            clsSQL = Nothing
        End Try
    End Function
End Class
